<template>
  <div class="_wz_cent_main _wz_transportVehicle">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="车牌号">
          <i-input v-model="formDataSearch.carPlateNo" placeholder="请填写车牌号" clearable />
        </FormItem>
        <FormItem label="车辆颜色">
          <i-select v-model.number="formDataSearch.carPlateColor" filterable placeholder="请选择车辆颜色" clearable>
            <Option :value="1">蓝色</Option>
            <Option :value="2">黄色</Option>
            <Option :value="3">黑色</Option>
            <Option :value="4">白色</Option>
            <Option :value="5">绿色</Option>
            <Option :value="93">黄绿色</Option>
            <Option :value="9">其他</Option>
          </i-select>
        </FormItem>
        <FormItem label="车架号" v-if="searchType">
          <i-input v-model="formDataSearch.frameNo" placeholder="请填写车架号" clearable />
        </FormItem>
        <FormItem label="自编号" v-if="searchType">
          <i-input v-model="formDataSearch.customNo" placeholder="请填写自编号" clearable />
        </FormItem>
        <FormItem label="归属部门" v-if="searchType">
          <i-input v-model="formDataSearch.inOrgName" placeholder="请填写归属部门" clearable />
        </FormItem>
        <FormItem label="运输企业" v-if="searchType && !seeCarData">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="入网状态" v-if="searchType">
          <i-select v-model.number="formDataSearch.internetState" filterable placeholder="请选择入网状态" clearable>
            <Option :value="0">未入网</Option>
            <Option :value="1">已入网</Option>
            <Option :value="2">超时入网</Option>
          </i-select>
        </FormItem>
        <FormItem label="动态监管" v-if="searchType">
          <i-select v-model.number="formDataSearch.monitorState" filterable placeholder="请选择动态监管" clearable>
            <Option :value="0">未绑定</Option>
            <Option :value="1">已绑定</Option>
          </i-select>
        </FormItem>
        <FormItem label="主动安全" v-if="searchType">
          <i-select v-model.number="formDataSearch.videoState" filterable placeholder="请选择主动安全" clearable>
            <Option :value="0">未开启</Option>
            <Option :value="1">已开启</Option>
          </i-select>
        </FormItem>
        <FormItem label="行驶证状态" v-if="searchType">
          <i-select v-model.number="formDataSearch.permitState" filterable placeholder="请选择行驶证状态" clearable>
            <Option :value="0">已到期</Option>
            <Option :value="1">未到期</Option>
            <Option :value="2">即将到期</Option>
            <Option :value="-1">未知</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra" v-if="!seeCarData">
        <Button type="primary" @click="addTableData">添加</Button>
        <Button type="success" @click="vehicleExport">导出</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <!--添加修改-->
    <Drawer :title="formTitle" v-model="formOperation" width="1100" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <transportVehicleAdd v-if="formOperation" @closeFun="closeFun" :selectData="selectData"></transportVehicleAdd>
    </Drawer>

    <Drawer title="详情" v-model="vehicleDetailsType" width="900" :draggable="true">
      <vehicleDetails v-if="vehicleDetailsType" :selectData="selectData"></vehicleDetails>
    </Drawer>
    <Spin size="large" fix v-if="spinShow"></Spin>


  </div>
</template>
<script>

  import transportVehicleAdd from './transportVehicleAdd.vue'
  import vehicleDetails from './vehicleDetails.vue'
  import wzTbale from "../../../components/table/table";


  export default {
    props: ['seeCarData'],//接收来自父组件的数据
    components: {
      transportVehicleAdd,//添加
      vehicleDetails,//车辆详情
      wzTbale,//列表
    },

    data() {
      return {
        spinShow:false,//本页加载
        searchType:false,//搜索条件
        subDeptList :[],//下级企业
        vehicleDetailsType: false,//车辆详情
        formDataSearch: {
          deptUuid:!!this.seeCarData?this.seeCarData.deptUuid:''
        },//搜索条件
        formOperation: false,//表单左侧移出
        formOperationStyles: {//表单左侧移出css
          height: 'calc(100% - 55px)',
          overflow: 'auto',
          paddingBottom: '53px',
          position: 'static'
        },
        formTitle: "",//表单名称
        selectData: {},//选择数据
        tableData: {
          url: this.apiUrl.coreVehicleCoreVehiclePageList,//请求地址
          method: 'post',//请求方式
          where: {deptUuid:!!this.seeCarData?this.seeCarData.deptUuid:''},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '自编号', minWidth: 100, key: 'customNo', render: (h, params) => {
                return h('span', !!params.row.customNo ? params.row.customNo : "--");
              }
            },
            {title: '车牌号', minWidth: 110, key: 'carPlateNo'},
            {title: '车辆颜色', minWidth: 110, key: 'carPlateColor', render: (h, params) => {
                if (params.row.carPlateColor == 1) {
                  return h('Tag',{  props: { color: 'primary'}}, '蓝色');
                }else if (params.row.carPlateColor == 2) {
                  return h('Tag',{  props: { color: 'warning'}},  '黄色');
                }else if (params.row.carPlateColor == 3) {
                  return h('Tag',{  props: { color: '#515a6e'}},  '黑色');
                }else if (params.row.carPlateColor == 4) {
                  return h('Tag',{  props: { color: 'default'}},  '白色');
                }else if (params.row.carPlateColor == 5) {
                  return h('Tag',{  props: { color: 'success'}},  '绿色');
                }else if (params.row.carPlateColor == 93) {
                  return h('Tag',{  props: { color: '#8ebe19'}},  '黄绿色');
                }else if (params.row.carPlateColor == 9) {
                  return h('Tag',{  props: { color: 'blue'}},  '其他');
                }else{
                  return h('Tag',{  props: {color: 'blue'}},  '未获取颜色');
                }
              }
            },
            {title: '车架号', minWidth: 170, key: 'frameNo'},
            // {title: '车主业户', minWidth: 160, key: 'vehicleOwnerName'},
            // {title: '联系电话', minWidth: 120, key: 'vehicleOwnerPhone'},
            {title: '联系人', minWidth: 160, key: 'vehicleContactsName'},
            {title: '联系电话', minWidth: 120, key: 'vehicleContactsPhone'},
            {title: '车辆类型', minWidth: 130, key: 'vehicleType'},
            {title: '初登日期', minWidth: 120, key: 'vehicleDrivingPermitRegisterDate', render: (h, params) => {
                return h('span', !!params.row.vehicleDrivingPermitRegisterDate ? params.row.vehicleDrivingPermitRegisterDate : "--");
              }
            },
            {title: '到期日期', minWidth: 120, key: 'vehicleDrivingPermitExpireDate', render: (h, params) => {
                return h('span', !!params.row.vehicleDrivingPermitExpireDate ? params.row.vehicleDrivingPermitExpireDate : "--");
              }
            },
            {title: '归属部门', minWidth: 160, key: 'inOrgName'},
            {title: '运输企业', minWidth: 260, key: 'deptName'},

            {title: '入网状态', minWidth: 140,
              render: (h, params) => {
                if (params.row.internetState == 0) {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未入网')
                } else if (params.row.internetState == 1){
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '已入网')
                } else if (params.row.internetState == 2){
                  return h('Tag', {props: {type: 'dot',color: 'error'}}, '超时入网')
                }
              }
            },
            {title: '动态监管', minWidth: 130,
              render: (h, params) => {
                if (params.row.monitorState == 0) {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未绑定')
                } else if (params.row.monitorState == 1){
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '已绑定')
                }
              }
            },
            {title: '主动安全', minWidth: 130,
              render: (h, params) => {
                if (params.row.videoState == 0) {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未开启')
                } else if (params.row.videoState == 1){
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '已开启')
                }
              }
            },
            {title: '行驶证状态', minWidth: 140,
              render: (h, params) => {
                if (params.row.permitState == 0) {
                  return h('Tag', {props: {type: 'dot',color: 'error'}}, '已到期')
                } else if (params.row.permitState == 1){
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '未到期')
                } else if (params.row.permitState == 2){
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '即将到期')
                } else if (params.row.permitState == -1){
                  return h('Tag', {props: {type: 'dot',color: ''}}, '未知')
                }
              }
            },
            {
              title: '操作', key: 'value', fixed: 'right', width: 150, render: (h, params) => {
                let operationButtons = [];
                //查看
                operationButtons.push(

                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.selectData = params.row;
                        this.vehicleDetailsType = true;
                      }
                    }
                  }, '查看')
                );
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //画像
                operationButtons.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        let that = this;
                        let routeData = that.$router.resolve({
                          name: "vehiclePortrait",
                          query: { uuid: params.row.uuid },
                        });
                        window.open(routeData.href, '_blank');

                      }
                    }
                  }, '画像')
                );

                if(!this.seeCarData){
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                  //修改
                  operationButtons.push(
                    h('span', {
                      style: {"color": "#2d8cf0", "cursor": "pointer"},
                      on: {
                        click: () => {
                          this.formTitle = "修改";
                          this.selectData = JSON.parse(JSON.stringify(params.row))
                          this.formOperation = true;
                        }
                      }
                    }, '修改')
                  );
                }

                return operationButtons;
              }
            },
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态
    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;
      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
          if (!!res) {
            that.subDeptList = res.data.data;
          }
        }).catch(err => {
        console.log("失败", err)
      })
    },
    methods: {//执行的方法
      //搜索
      searchSubmit() {
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      //添加
      addTableData() {
        let that = this;
        that.formTitle = "添加";
        that.selectData = {}
        that.formOperation = true;
      },
      //添加修改触发后关闭刷新
      closeFun(data) {
        let that = this;
        if (data) {//添加修改 刷新表单
          that.$refs.wzTbale.tableLoadData();
        }
        that.formOperation = false;
      },
      //车辆导出
      vehicleExport() {
        let that = this;
        that.spinShow = true;
        that.axios.post(that.apiUrl.coreVehicleCoreVehicleExport,  that.formDataSearch).then(res => {
          that.spinShow = false;
          if (!!res) {
            window.open(that.apiUrl.imgUrl + res.data.data)
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_transportVehicle { //不固定头部  列表到底
    display: flex;
    flex-direction: column;
  }
</style>
